﻿// Decompiled with JetBrains decompiler
// Type: Commom.Util.RandomNumber
// Assembly: MT5Trade, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8045A2CB-DBD6-41AD-8804-F98CAC1BDC8D
// Assembly location: C:\projects\trade\trade_tool\trade0812\MT5Trade.dll

using System;
using System.Text;

#nullable enable
namespace Commom.Util;

public class RandomNumber
{
  public static string AllChar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,a,b,c,d,e,f,g,h,i,g,k,l,m,n,o,p,q,r,F,G,H,I,G,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,s,t,u,v,w,x,y,z";
  public static object _lock = new object();
  public static int ID = 621516;

  public static string GetSequence()
  {
    lock (RandomNumber._lock)
    {
      Random random = new Random(RandomNumber.GetRandomSeed());
      return DateTime.Now.ToString("yyyyMMddHHmmss") + random.Next(1000, 9999).ToString();
    }
  }

  public static string GetSnSequence()
  {
    lock (RandomNumber._lock)
    {
      Random random = new Random(RandomNumber.GetRandomSeed());
      return DateTime.Now.ToString("HHmmssfff") + random.Next(1000, 9999).ToString();
    }
  }

  public static string GetMoney()
  {
    lock (RandomNumber._lock)
    {
      Random random = new Random(RandomNumber.GetRandomSeed());
      RandomNumber.ID += random.Next(11, 99);
      return RandomNumber.ID.ToString();
    }
  }

  public static double GetFloatRandNum(double min, double max, int len1)
  {
    return Math.Round(new Random(RandomNumber.GetRandomSeed()).NextDouble(min, max), len1);
  }

  public static string CreateRandomCode(int codeCount)
  {
    string[] strArray = RandomNumber.AllChar.Split(',');
    StringBuilder data = new StringBuilder();
    int length = strArray.Length;
    for (int index1 = 0; index1 < codeCount; ++index1)
    {
      int index2 = new Random(RandomNumber.GetRandomSeed()).Next(length);
      data.Append(strArray[index2]);
    }
    return data.ToStr();
  }

  public static string CreateRandomNumCode(int codeCount)
  {
    string[] strArray = "0,1,2,3,4,5,6,7,8,9".Split(',');
    int length = strArray.Length;
    StringBuilder data = new StringBuilder();
    for (int index1 = 0; index1 < codeCount; ++index1)
    {
      int index2 = new Random(RandomNumber.GetRandomSeed()).Next(length);
      data.Append(strArray[index2]);
    }
    return data.ToStr();
  }

  public static int GetRandomSeed() => (int) DateTime.Now.Ticks;
}
